module.exports = {
  apps: [{
    name: "api",
    script: "dist/src/main.js",
    interpreter: "node",
    instances: "max", // Use maximum number of CPU cores
    exec_mode: "cluster", // Run in cluster mode for load balancing
    watch: false, // Don't watch for file changes in production
    max_memory_restart: process.env.MAX_MEMORY_RESTART || "8G", // Configurable via environment variable
    env: {
      NODE_ENV: process.env.NODE_ENV || "production",
    },
    // Log configuration
    log_date_format: "YYYY-MM-DD HH:mm:ss Z",
    error_file: "./logs/error.log",
    out_file: "./logs/out.log",
    merge_logs: true,
    // Log rotation settings
    log_type: "json",
    max_logs: "30d", // Keep logs for 30 days
    log_size: "10G", // Rotate when log size reaches 10GB
    compress: true, // Compress rotated logs
    // Graceful shutdown
    kill_timeout: 5000, // Wait 5 seconds for graceful shutdown
    // Health check
    exp_backoff_restart_delay: 100, // Exponential backoff for restarts
  }]
}; 